package com.lemurian.bankdata.action.business;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

import com.lemurian.bankdata.bean.ClientDocumentDAO;
import com.lemurian.bankdata.dto.DokumenHelper;
import com.lemurian.bankdata.dto.LogHelper;
import com.lemurian.bankdata.lite.authentication.BankDataPrincipal;
import com.lemurian.bankdata.lite.enums.ApplicationCategory;
import com.lemurian.bankdata.lite.enums.UserActivityType;
import com.lemurian.bankdata.lite.enums.UserType;
import com.lemurian.bankdata.lite.logger.BankDataLogger;
import com.lemurian.bankdata.lite.struts.Pager;
import com.lemurian.bankdata.lite.struts.PartialList;
import com.lemurian.bankdata.lite.utils.GeneralConstant;
import com.lemurian.bankdata.lite.utils.GlobalFunction;
import com.lemurian.bankdata.services.ActivityLogService;
import com.lemurian.bankdata.services.CategoryService;
import com.lemurian.bankdata.services.CertificateService;
import com.lemurian.bankdata.services.ClientCertificateService;
import com.lemurian.bankdata.services.ClientDocumentService;
import com.lemurian.bankdata.services.ClientService;
import com.lemurian.bankdata.services.DebiturService;
import com.lemurian.bankdata.services.ManagementClientTypeService;
import com.lemurian.bankdata.services.ManagementService;
import com.lemurian.bankdata.services.SellerService;
import com.lemurian.bankdata.services.SignatureScheduleService;
import com.lemurian.bankdata.services.TaxService;
import com.lemurian.bankdata.utils.BaseAction;
import com.lemurian.entity.Category;
import com.lemurian.entity.Certificate;
import com.lemurian.entity.Client;
import com.lemurian.entity.ClientCertificate;
import com.lemurian.entity.ClientDocument;
import com.lemurian.entity.Debitur;
import com.lemurian.entity.Management;
import com.lemurian.entity.ManagementClientType;
import com.lemurian.entity.Seller;
import com.lemurian.entity.SignatureSchedule;
import com.lemurian.entity.Tax;
import com.lemurian.entity.User;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("serial")
public class PenandatangananAction extends BaseAction implements Preparable {

	private BankDataLogger log = BankDataLogger.getLogger(PenandatangananAction.class.getSimpleName());
	
	private Debitur debitur = new Debitur();
	private Seller seller =  new Seller();
	private Category departemen;
	private SignatureSchedule signatureSchedule = new SignatureSchedule();
	private Tax tax = new Tax();
	
	private static Client klien = new Client();
	private List<Client> listKlien;
	
	private List<Category> listTipeDepartemen;
	private int departemenId;
	
	private List<Category> listStatusPembeli;
	private int statusPembeliId;
	private int statusPasanganKawinPembeliId;
	
	private List<Category> listAktaNotaris;
	private String[] aktaNotarisIds;
	private List<Integer> listAktaNotarisId = new ArrayList<Integer>();
	
	private List<Category> listKepengurusanNotaris;
	private String[] kepengurusanNotarisIds;
	private List<Integer> listKepengurusanNotarisId = new ArrayList<Integer>();
	
	private List<Category> listAktaPPAT;
	private String[] aktaPPATIds;
	private List<Integer> listAktaPPATId = new ArrayList<Integer>();
	
	private List<Category> listKepengurusanPPAT;
	private String[] kepengurusanPPATIds;
	private List<Integer> listKepengurusanPPATId = new ArrayList<Integer>();
	
	private List<Category> listJenisDokumen;
	private String[] jenisDokumenIds;
	private List<Integer> listDokumenId = new ArrayList<Integer>();
	private List<Integer> listKeteranganDokumenId = new ArrayList<Integer>();
	private List<DokumenHelper> listDokumenHelper = new ArrayList<DokumenHelper>();
	
	private List<Category> listKeteranganDokumen;
	private String[] keteranganDokumenIds;
	
	private List<Category> listBank;
	private int bankId;
	
	private int id = 0;
	private String btn = "";
	
	private String[] selectedRows;
	
	private String namaDebitur = "";
	
	private String namaSertifikat = "";
	private String nomorSertifikat = "";
	private List<Certificate> listSertifikat;
	
	private String nominalPajakSSB = "";
	private String nominalPajakSSP = "";
	private String tanggalPembayaran = "";

	private String tglTTD = "";
	private String jamTTD = "";
	private String tempatTTD = "";
	
	private int isNotaris = 1;
	private int isPPAT = 1;
	
	private User user;
	private BankDataPrincipal principal;
	
	private String message = "";
	
	private DateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm");
	private DateFormat dateonly = new SimpleDateFormat("dd-MM-yyyy");
	
	@Autowired private ClientService clientService;
	@Autowired private CategoryService categoryService;
	@Autowired private TaxService taxService;
	@Autowired private DebiturService debiturService;
	@Autowired private SellerService sellerService;
	@Autowired private SignatureScheduleService signatureScheduleService;

	@Autowired private ClientCertificateService aktaKlienService;
	@Autowired private ManagementClientTypeService kepengurusanKlienService;
	@Autowired private ClientDocumentService dokumenKlienService;
	@Autowired private ManagementService prosesKepengurusanService;
	
	@Autowired private CertificateService certificateService;
	@Autowired static ClientDocumentDAO clientDocumentDAO;

	@Autowired 
	private ActivityLogService userActivityLogService;
	private LogHelper userActivityLog;

	private boolean PT;

	@Override
	public void prepare() throws Exception {
		principal = (BankDataPrincipal) getSession().get(GeneralConstant.USER_PRINCIPAL);
		user = principal.getUser();
		
		log.sInfo("get client id [%s]", id);
        if (id > 0 && btn.equalsIgnoreCase("aktaKepengurusan")) {
        	log.info("on akta kepengurusan page");
			klien = clientService.loadClientOnly(id);
			
			// === looking for AKTA KLIEN ===
			List<ClientCertificate> listAktaKlien = aktaKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
	    	log.sInfo("found total list akta klien : " + listAktaKlien.size());
	    	klien.setClientCertificates(listAktaKlien);
	    	
	    	// === looking for KEPENGURUSAN KLIEN ===
	    	List<ManagementClientType> listKepengurusanKlien = kepengurusanKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
	    	log.sInfo("found total list kepengurusan klien", listKepengurusanKlien.size());
	    	klien.setManagementClientTypes(listKepengurusanKlien);
	    	
	    	// === looking for DOKUMEN KLIEN ===
	    	List<ClientDocument> listDokumenKlien = dokumenKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
	    	log.sInfo("found total list dokumen klien [%s]", listDokumenKlien.size());
	    	klien.setClientDocuments(listDokumenKlien);
	    	
		} else if (id > 0) {
			log.info("on penandatanganan / pilih akta page");
        	klien = clientService.load(id);
        	tax= taxService.findTaxByClient(klien);
        	//signatureSchedule = signatureScheduleService.findSignatureScheduleByClient(klien);
        } else {
        	klien = new Client();
        }
	}
	
	public String sertifikatAdd() {
		setMappedRequest("saveSertifikat");
		return SUCCESS;
	}
	
	public String cariSertifikat() {
		try {
			PartialList<Certificate> partialList = certificateService.findByCriteria(getStart(), getCount(),
					getAscDesc().equalsIgnoreCase("desc") ? Order.desc(getOrderBy().length() > 0 ? getOrderBy() : "name") : Order.asc(getOrderBy().length() > 0 ? getOrderBy() : "name"),
					namaSertifikat != null && !namaSertifikat.equalsIgnoreCase("") ? Restrictions.ilike("name", namaSertifikat, MatchMode.ANYWHERE) : Restrictions.ne("id", new Integer(-1)),
                    nomorSertifikat != null && !nomorSertifikat.equalsIgnoreCase("") ? Restrictions.ilike("number", nomorSertifikat, MatchMode.ANYWHERE) : Restrictions.ne("id", new Integer(-1)),
                    Restrictions.isNull("client")
                    );

            listSertifikat = partialList.getList();
            log.sInfo("found [%s] sertifikat", listSertifikat.size());

            setPager(Pager.generatePager(getStart(), getCount(), partialList.getTotal()));
            setPagerItem(Pager.generatePagerItem(getStart(), getCount(), partialList.getTotal()));

            partialList = null;
            
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		setMappedRequest("saveSertifikat");
		return SUCCESS;
	}
	
	public String saveSertifikat() {
		try {
			log.sInfo("Total Checked [%s]", selectedRows.length);
			for (int i = 0; i < selectedRows.length; i++) {
				log.sInfo("Rows check [%s]", selectedRows[i]);
				int sertifikatId = Integer.parseInt(GlobalFunction.decodeParameter(selectedRows[i]));
				Certificate sertifikat = certificateService.findById(sertifikatId);
				if (sertifikat != null) {
					log.sInfo("found sertifikat with name [%s]", sertifikat.getName());
					log.sInfo("klien with debitur name [%s]", klien.getDebitur().getName());
					clientService.save(klien);
					sertifikat.setClient(klien);
					certificateService.save(sertifikat);
					
					userActivityLog = new LogHelper(user, UserActivityType.REJECT_AO_FOR_CLIENT);
					
		            try {
		                log.sInfo(" :: User [%s:%s] is successfully assign a certificate [%s] to client [%s]", user.getId(), user.getName(), sertifikat.getName(), klien.getDebitur().getName());

		                //check if activity is success
		                userActivityLog.setStatus(LogHelper.SUCCESS_ACTIVITY);
		                
		            } catch (Exception e) {
		                log.sInfo(" :: Error was raised when User [%s:%s] reject a certificate [%s]", user.getId(), user.getName(), sertifikat.getName());
		                
		                //set activity log status into failed
		                userActivityLog.setStatus(LogHelper.FAILED_ACTIVITY);
		                userActivityLog.setErrorMsg(e.getMessage());
		            }
		            //save activity log
		            userActivityLog.setSessionId(ServletActionContext.getRequest().getSession().getId());
		            userActivityLog.getAdditionalParams().add(sertifikat.getName());
		            userActivityLogService.saveUserActivity(userActivityLog);
				}
			}
			message = "Pemilihan sertifikat sukses";
            addCustomActionMessage(message);
			
		} catch (Exception e) {
			e.printStackTrace();
			message = "Maaf terjadi kesalahan, message : "+e.getMessage();
            addCustomActionError(message);
		}
		setMappedRequestFullPath("/PenandatangananAction_list.do");
        return GeneralConstant.REDIRECT;
	}
	
	@Override
	@SkipValidation
	public String list() {		
		log.info("list Klien yang sudah disetujui");
		setPreviousPage(GeneralConstant.LIST);
		try {
			PartialList<Client> partialList = clientService.findClientForPenandatanganan(getStart(), getCount(),
					getAscDesc().equalsIgnoreCase("desc") ? Order.desc(getOrderBy().length() > 0 ? getOrderBy() : "createDate") : Order.asc(getOrderBy().length() > 0 ? getOrderBy() : "createDate"),
	                namaDebitur != null && namaDebitur.length() > 0 ? Restrictions.ilike("debitur.name", namaDebitur, MatchMode.ANYWHERE) : Restrictions.ne("id", new Integer(-1))
	                );
	
	        setListKlien(partialList.getList());
	        log.sInfo("found [%s] client(s)", getListKlien().size());
	
	        setPager(Pager.generatePager(getStart(), getCount(), partialList.getTotal()));
	        setPagerItem(Pager.generatePagerItem(getStart(), getCount(), partialList.getTotal()));
	
	        partialList = null;
	
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	    setMappedRequest(GeneralConstant.LIST);
	    return SUCCESS;
	}
	
	@Override
	@SkipValidation
	public String add() {
		log.info("on input form penandatanganan page ..");
	    setMappedRequest(GeneralConstant.SAVE);
	    setPreviousPage(GeneralConstant.ADD);
	    try {
	    	
	    	if (id > 0) {
		    	debitur = klien.getDebitur() != null ? klien.getDebitur() : new Debitur();
	    		seller = klien.getSeller() != null ?  klien.getSeller() : new Seller();
	    		// find tax
	    		System.out.println("klien id : " + klien.getId());
	    		
	    		if (tax != null && tax.getId() > 0) {
	    			log.sInfo("found tax nominal SSB for this client [%s]", tax.getNominalSSB());
	    			log.sInfo("found tax nominal SSP for this client [%s]", tax.getNominalSSP());
	    			if (tax.getNominalSSB() != null) {
	    				nominalPajakSSB = tax.getNominalSSB().toString();
						nominalPajakSSB = nominalPajakSSB.replace(".00", "");	
					}
	    			
	    			if (tax.getNominalSSP() != null) {
	    				nominalPajakSSP = tax.getNominalSSP().toString();
						nominalPajakSSP = nominalPajakSSP.replace(".00", "");	
					}
	    			
			    	if (tax.getPaymentDate() != null) {
						tanggalPembayaran = dateonly.format(tax.getPaymentDate());	
					}
				}
	    		
	    	}
	    	// Get Tipe Kepengurusan
	    	listTipeDepartemen = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.TIPE_DEPARTEMEN.code())));
	    	log.sInfo("found listTipeDepartemen [%s]", listTipeDepartemen.size());
	    	
	    	listStatusPembeli = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.STATUS_PEMBELI.code())));
	    	log.sInfo("found listStatusPembeli [%s]", listStatusPembeli.size());
	    	
	    	listBank = categoryService.findByCriteria(Order.asc("name"), Restrictions.eq("parent.id", ApplicationCategory.BANK.code()));
	    	log.sInfo("found listBank [%s]", listBank.size());
	    	
	    	// Drop down value
	    	if (klien.getDepartment() != null) {
				setDepartemenId(klien.getDepartment().getId());
				log.sInfo("Get department ID [%s]", departemenId);
			}
	    	
	    	if (klien.getBank() != null) {
				bankId = klien.getBank().getId();
				log.sInfo("Get bank ID [%s]", bankId);
			}
	    	
	    	if (debitur.getStatus() != null) {
				statusPembeliId = debitur.getStatus().getId();
				log.sInfo("Get status debitur ID [%s]", statusPembeliId);
			}
	    	
	    	if (debitur.getMarriedCoupleStatus() != null) {
				statusPasanganKawinPembeliId = debitur.getMarriedCoupleStatus().getId();
				log.sInfo("Get status pasangan kawin debitur ID [%s]", statusPasanganKawinPembeliId);
			}
	    	
		} catch (Exception e) {
			e.printStackTrace();
		}
	    return SUCCESS;
	}

	@Override
	public String save() {
		log.info("on save klien action .. ");
		String message = "";
		String warningMessage = "";
		try {
			// Set Departement
			if (departemenId > 0) {
				Category department = categoryService.findById(departemenId);
				klien.setDepartment(department);	
			} else {
				warningMessage += "Departemen belum diisi. ";
			}
			
			// Set debitur
			if (statusPembeliId > 0) {
				Category statusPembeli = categoryService.findById(statusPembeliId);
				debitur.setStatus(statusPembeli);	
			}
			if (statusPasanganKawinPembeliId > 0) {
				Category statusPasanganKawinPembeli = categoryService.findById(statusPasanganKawinPembeliId);
				debitur.setMarriedCoupleStatus(statusPasanganKawinPembeli);
			}
			
			// Set Bank
			if (bankId > 0) {
				Category bank = categoryService.findById(bankId);
				klien.setBank(bank);	
			} else {
				warningMessage += "Bank belum diisi. ";
			}
			
			// Set Tax
			log.sInfo("tax for this client (SSB) [%s]", nominalPajakSSB);
			log.sInfo("tax for this client (SSP) [%s]", nominalPajakSSP);
			log.sInfo("tax for this client [%s]", tanggalPembayaran + " 00:00");
			
			clientService.save(klien);
			
			tax.setClient(klien);
			if (tax.getId() == 0) {
				tax.setCreateBy(user.getLoginId());
				tax.setCreateDate(new Timestamp(System.currentTimeMillis()));
			} else {
				tax.setUpdateBy(user.getLoginId());
				tax.setUpdateDate(new Timestamp(System.currentTimeMillis()));
			}
			
			if (nominalPajakSSB != null && nominalPajakSSB.length() != 0) {
				tax.setNominalSSB(BigDecimal.valueOf(Double.valueOf(nominalPajakSSB)));	
			}
			
			if (nominalPajakSSP != null && nominalPajakSSP.length() != 0) {
				tax.setNominalSSP(BigDecimal.valueOf(Double.valueOf(nominalPajakSSP)));	
			}
			
			if (tanggalPembayaran != null && tanggalPembayaran.length() != 0) {
				tax.setPaymentDate(df.parse(tanggalPembayaran + " 00:00"));
			} else {
				tax.setPaymentDate(null);
			}
			
			
			// Set Jadwal TTD
			if (departemenId > 0) {
				if (departemenId == ApplicationCategory.DEPARTEMEN_PPAT_NOTARIS.code()) {
					
					// Buat 2 jadwal yang berbeda ditiap department
					// == PPAT
					Category departmentPPAT = categoryService.findById(ApplicationCategory.DEPARTEMEN_PPAT.code());
					SignatureSchedule jadwalPPAT = signatureScheduleService.findScheduleByClientAndDepartment(klien, departmentPPAT);
					if (jadwalPPAT == null) {
						jadwalPPAT = new SignatureSchedule();
						jadwalPPAT.setClient(klien);
						jadwalPPAT.setDepartment(departmentPPAT);
						signatureScheduleService.save(jadwalPPAT);
					}
					
					// == NOTARIS
					Category departmentNotaris = categoryService.findById(ApplicationCategory.DEPARTEMEN_NOTARIS.code());
					SignatureSchedule jadwalNotaris = signatureScheduleService.findScheduleByClientAndDepartment(klien, departmentNotaris);
					if (jadwalNotaris == null) {
						jadwalNotaris = new SignatureSchedule();
						jadwalNotaris.setClient(klien);	
						jadwalNotaris.setDepartment(departmentNotaris);
						signatureScheduleService.save(jadwalNotaris);
					}
					
				} else if (departemenId == ApplicationCategory.DEPARTEMEN_PPAT.code()) {
					// == PPAT
					Category departmentPPAT = categoryService.findById(ApplicationCategory.DEPARTEMEN_PPAT.code());
					SignatureSchedule jadwalPPAT = signatureScheduleService.findScheduleByClientAndDepartment(klien, departmentPPAT);
					if (jadwalPPAT == null) {
						jadwalPPAT = new SignatureSchedule();
						jadwalPPAT.setClient(klien);
						jadwalPPAT.setDepartment(departmentPPAT);
						signatureScheduleService.save(jadwalPPAT);
					}
				} else if (departemenId == ApplicationCategory.DEPARTEMEN_NOTARIS.code()) {
					// == NOTARIS
					Category departmentNotaris = categoryService.findById(ApplicationCategory.DEPARTEMEN_NOTARIS.code());
					SignatureSchedule jadwalNotaris = signatureScheduleService.findScheduleByClientAndDepartment(klien, departmentNotaris);
					if (jadwalNotaris == null) {
						jadwalNotaris = new SignatureSchedule();
						jadwalNotaris.setClient(klien);	
						jadwalNotaris.setDepartment(departmentNotaris);
						signatureScheduleService.save(jadwalNotaris);
					}
				}	else {
					// Unknown department
				}
			}
			
			taxService.save(tax);
			debiturService.save(debitur);
			sellerService.save(seller);
			
			Set<SignatureSchedule> sigSchedules = new HashSet<SignatureSchedule>();
			sigSchedules.add(signatureSchedule);
			Set<Tax> taxes = new HashSet<Tax>();
			taxes.add(tax);
			
			klien.setDebitur(debitur);
			klien.setSeller(seller);
			klien.setTaxes(taxes);
			klien.setSignatureSchedules(sigSchedules);
			
			clientService.save(klien);
			message = "Data klien berhasil disimpan";
			log.info(message);
			log.info(warningMessage);
			
			addCustomActionMessage(message);
			
			if (!warningMessage.equalsIgnoreCase("")) {
				addCustomActionWarning(warningMessage);	
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			message = "Maaf terjadi kesalahan : " + e.getMessage();
			addCustomActionError(message);
		}
		setMappedRequestFullPath("PenandatangananAction_list.do");
		return GeneralConstant.REDIRECT;
	}
	
	public String aktaKepengurusanAdd() {
		setMappedRequest("saveAktaKepengurusan");
	    setPreviousPage("addAktaKepengurusan");
		log.info("on choosing kepengurusan and akta");
		try {
			
			if (klien.getDepartment().getId() == ApplicationCategory.DEPARTEMEN_PPAT.code()) {
				isNotaris = 0;
			} else if (klien.getDepartment().getId() == ApplicationCategory.DEPARTEMEN_NOTARIS.code()) {
				isPPAT = 0;
			}
			
			log.sInfo("got client with sertifikat name [%s]", klien.getDebitur().getName());
			if (klien.getIsPT() == null) {
				PT = false;
			} else {
				PT = klien.getIsPT();
			}
			
			log.sInfo("got client with debitur name [%s]", klien.getDebitur().getName());
			
			listAktaNotaris = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.AKTA_NOTARIS.code())));
	    	log.sInfo("found listAktaNotaris [%s]", listAktaNotaris.size());
	    	
	    	listKepengurusanNotaris = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.KEPENGURUSAN_NOTARIS.code())));
	    	log.sInfo("found listKepengurusanNotaris [%s]", listKepengurusanNotaris.size());
	    	
	    	listAktaPPAT = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.AKTA_PPAT.code())));
	    	log.sInfo("found listAktaPPAT [%s]", listAktaPPAT.size());
	    	
	    	listKepengurusanPPAT = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.KEPENGURUSAN_PPAT.code())));
	    	log.sInfo("found listKepengurusanPPAT [%s]", listKepengurusanPPAT.size());
	    	
	    	listJenisDokumen = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.JENIS_DOKUMEN.code())));
	    	log.sInfo("found listJenisDokumen [%s]", listJenisDokumen.size());
	    	for (Category jenis : listJenisDokumen) {
				DokumenHelper dokHelper = new DokumenHelper();
				dokHelper.setJenis(jenis);
				listDokumenHelper.add(dokHelper);
			}
	    	
	    	listKeteranganDokumen = categoryService.findByCriteria(Order.asc("id"),(Restrictions.eq("parent.id", ApplicationCategory.KETERANGAN_DOKUMEN.code())));
	    	
	    	for (ClientCertificate aktaKlien : klien.getClientCertificates()) {
	    		if (aktaKlien.getCertificateType().getParent().getId() == ApplicationCategory.AKTA_PPAT.code()) {
	    			listAktaPPATId.add(aktaKlien.getCertificateType().getId());
				} else if (aktaKlien.getCertificateType().getParent().getId() == ApplicationCategory.AKTA_NOTARIS.code()) {
					listAktaNotarisId.add(aktaKlien.getCertificateType().getId());
				}
			}
	    	
	    	for (ManagementClientType kepengurusanKlien : klien.getManagementClientTypes()) {
	    		if (kepengurusanKlien.getManagementType().getParent().getId() == ApplicationCategory.KEPENGURUSAN_PPAT.code()) {
	    			listKepengurusanPPATId.add(kepengurusanKlien.getManagementType().getId());	
	    		} else if (kepengurusanKlien.getManagementType().getParent().getId() == ApplicationCategory.KEPENGURUSAN_NOTARIS.code()) {
	    			listKepengurusanNotarisId.add(kepengurusanKlien.getManagementType().getId());
	    		}
	    	} 
	    	
	    	for (ClientDocument dokumenKlien : klien.getClientDocuments()) {
				listDokumenId.add(dokumenKlien.getDocumentType().getId());
				listKeteranganDokumenId.add(dokumenKlien.getDocumentRemarks().getId());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	public String saveAktaKepengurusan() {
		try {
			log.info("saving akta klien dan kepengurusan klien");
			
			List<ClientCertificate> listAktaKlien = aktaKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
			List<ClientCertificate> listAktaKlienUnused = new ArrayList<ClientCertificate>();
			
			List<ManagementClientType> listKepengurusanKlien = kepengurusanKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
			List<ManagementClientType> listKepengurusanKlienUnused = new ArrayList<ManagementClientType>();
			
			List<Integer> listAktaKlienNotarisIdsStored = new ArrayList<Integer>();
			List<Integer> listAktaKlienPPATIdsStored = new ArrayList<Integer>();
			List<Integer> listKepengurusanKlienNotarisIdsStored = new ArrayList<Integer>();
			List<Integer> listKepengurusanKlienPPATIdsStored = new ArrayList<Integer>();
			
			for (ClientCertificate type : listAktaKlien) {
				if (type.getCertificateType().getParent().getId() == ApplicationCategory.AKTA_NOTARIS.code()) {
					listAktaKlienNotarisIdsStored.add(type.getCertificateType().getId());
				} else if (type.getCertificateType().getParent().getId() == ApplicationCategory.AKTA_PPAT.code()) {
					listAktaKlienPPATIdsStored.add(type.getCertificateType().getId());
				}
			}

			for (ManagementClientType type : listKepengurusanKlien) {
				if (type.getManagementType().getParent().getId() == ApplicationCategory.KEPENGURUSAN_NOTARIS.code()) {
					listKepengurusanKlienNotarisIdsStored.add(type.getManagementType().getId());
				} else if (type.getManagementType().getParent().getId() == ApplicationCategory.KEPENGURUSAN_PPAT.code()) {
					listKepengurusanKlienPPATIdsStored.add(type.getManagementType().getId());
				}
			}
			
			log.info("TOTAL listAktaKlienPPATIdsStored : " + listKepengurusanKlienPPATIdsStored.size());
			log.info("TOTAL listAktaKlienNotarisIdsStored : " + listKepengurusanKlienNotarisIdsStored.size());
			
			log.info("TOTAL listKepengurusanKlienPPATIdsStored : " + listKepengurusanKlienPPATIdsStored.size());
			log.info("TOTAL listKepengurusanKlienNotarisIdsStored : " + listKepengurusanKlienNotarisIdsStored.size());
			
			log.info("clean existing dokumen pelengkap klien first ..");
			List<ClientDocument> listDokumenKlien = dokumenKlienService.findByCriteria(Order.asc("id"), Restrictions.eq("client", klien));
			//List<ClientDocument> listDokumenKlienUnused = new ArrayList<ClientDocument>();
			for (ClientDocument clientDocument : listDokumenKlien) {
				dokumenKlienService.delete(clientDocument);
			}
			
			log.info("---------------------------------------------------------------------------------------------------------------");
			log.info("saving akta klien for PPAT");
			if (aktaPPATIds != null) {
				List<Integer> listAktaPPATIds = new ArrayList<Integer>();
				listAktaPPATIds = fillRawIds(aktaPPATIds);
				deleteUncheckedAkta(listAktaKlienNotarisIdsStored, listAktaPPATIds);
				savingAktaConfiguration(listAktaPPATIds);
				log.info("DONE!!");
			}
			log.info("---------------------------------------------------------------------------------------------------------------");			
			
			log.info("---------------------------------------------------------------------------------------------------------------");
			log.info("saving akta klien for Notaris");
			if (aktaNotarisIds != null) {
				List<Integer> listAktaNotarisIds = new ArrayList<Integer>();
				listAktaNotarisIds = fillRawIds(aktaNotarisIds);
				deleteUncheckedAkta(listAktaKlienNotarisIdsStored, listAktaNotarisIds);
				savingAktaConfiguration(listAktaNotarisIds);
				log.info("DONE!!");
			}
			log.info("---------------------------------------------------------------------------------------------------------------");
			
			log.info("---------------------------------------------------------------------------------------------------------------");
			log.info("saving kepengurusan klien for PPAT");
			if (kepengurusanPPATIds != null) {
				List<Integer> listKepengurusanPPATIds = new ArrayList<Integer>();
				listKepengurusanPPATIds = fillRawIds(kepengurusanPPATIds);				
				deleteUncheckedKepengurusan(listKepengurusanKlienPPATIdsStored, listKepengurusanPPATIds);
				savingKepengurusanConfiguration(listKepengurusanPPATIds);
				log.info("DONE!!");
			} else {
				log.info("THERE'S NO PPAT KEPENGURUSAN WAS CHECKED");
				for (Integer mctId : listKepengurusanKlienPPATIdsStored) {
					ManagementClientType mct = kepengurusanKlienService.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("managementType.id", mctId));
					log.info("found kepengurusan klien : [%s]. DELETE!", mct.getManagementType().getName());
					kepengurusanKlienService.delete(mct);
				}
			}
			log.info("---------------------------------------------------------------------------------------------------------------");
			
			log.info("---------------------------------------------------------------------------------------------------------------");
			log.info("saving kepengurusan klien for Notaris");
			if (kepengurusanNotarisIds != null) {
				List<Integer> listKepengurusanNotarisIds = new ArrayList<Integer>();
				listKepengurusanNotarisIds = fillRawIds(kepengurusanNotarisIds);
				deleteUncheckedKepengurusan(listKepengurusanKlienNotarisIdsStored, listKepengurusanNotarisIds);
				savingKepengurusanConfiguration(listKepengurusanNotarisIds);
				log.info("DONE!!");
			} else {
				log.info("THERE'S NO NOTARIS KEPENGURUSAN WAS CHECKED");
				for (Integer mctId : listKepengurusanKlienNotarisIdsStored) {
					ManagementClientType mct = kepengurusanKlienService.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("managementType.id", mctId));
					log.info("found kepengurusan klien : [%s]. DELETE!", mct.getManagementType().getName());
					kepengurusanKlienService.delete(mct);
				}
			}
			log.info("---------------------------------------------------------------------------------------------------------------");
			
			
			
			log.info("saving dokumen pelengkap klien");
			if (jenisDokumenIds != null) {
				for (int i = 0; i < jenisDokumenIds.length; i++) {
					log.info("jenis dokumen id : " + jenisDokumenIds[i]);
					log.info("ket dokumen id : " + keteranganDokumenIds[i]);	
					
					for (int j = 0; j < keteranganDokumenIds.length; j++) {
						String[] keteranganElement = keteranganDokumenIds[j].equalsIgnoreCase("") ? null : keteranganDokumenIds[j].split(";");
						if (keteranganElement != null && keteranganElement[1].equalsIgnoreCase(jenisDokumenIds[i])) {
							log.sInfo("jenis dok : %s, keterangan dok : %s", jenisDokumenIds[i], keteranganElement[0]);
							
							String dokumenId = GlobalFunction.decodeParameter(jenisDokumenIds[i]);
							String keteranganDokumenId = GlobalFunction.decodeParameter(keteranganElement[0]);
							Category dokumen = categoryService.findById(Integer.parseInt(dokumenId));
							Category keteranganDokumen = categoryService.findById(Integer.parseInt(keteranganDokumenId));
							
							log.sInfo("dokumen : %s [%s]", dokumen.getName(), keteranganDokumen.getName());
							
							ClientDocument dokumenKlien = new ClientDocument();
							dokumenKlien.setClient(klien);
							dokumenKlien.setDocumentType(dokumen);
							dokumenKlien.setDocumentRemarks(keteranganDokumen);
							dokumenKlien.setCreateDate(new Timestamp(System.currentTimeMillis()));
							dokumenKlien.setCreateBy(user.getLoginId());
							
							if (listDokumenId.contains(dokumenKlien.getDocumentType().getId())) {
								continue;
							}
							dokumenKlienService.save(dokumenKlien);
						}	
					}
				}
			}
			
			log.sInfo("klien berupa PT ? [%s]", PT);
			klien.setIsPT(PT);
			clientService.save(klien);
			
			addCustomActionMessage("Data berhasil disimpan");
		} catch (Exception e) {
			e.printStackTrace();
			addCustomActionError("Mohon maaf terjadi kesalahan : " + e.getMessage());
		}
		setMappedRequestFullPath("PenandatangananAction_list.do");
		return GeneralConstant.REDIRECT;
	}

	private List<Integer> fillRawIds(String[] aktaIds) {
		try {
			List<Integer>  list = new ArrayList<Integer>();
			for (int i = 0; i < aktaIds.length; i++) {
				list.add(Integer.parseInt(GlobalFunction.decodeParameter(aktaIds[i])));
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	private void deleteUncheckedAkta(List<Integer> listAktaKlienIdsStored, List<Integer> listAktaIdsChecked) {
		try {
			for (Integer typeId : listAktaKlienIdsStored) {
				log.info("got id : " + typeId);
				ClientCertificate clientCertificate = aktaKlienService
						.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("certificateType.id", typeId));
				
				if (clientCertificate != null) {
					log.info("got akta klien with akta : " + clientCertificate.getCertificateType().getName());
					if (!listAktaIdsChecked.contains(clientCertificate.getCertificateType().getId())) {
						log.info("unchecked, delete it..!");
						aktaKlienService.delete(clientCertificate);
					} else {
						log.info("still checked");
					}
				} else {
					log.info("akta client is null");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void deleteUncheckedKepengurusan(List<Integer> listKepengurusanKlienIdsStored, List<Integer> listKepengurusanIdsChecked) {
		try {
			// hapus kepengurusan yang di uncheck dari table tb_management_client_type
			for (Integer typeId : listKepengurusanKlienIdsStored) {
				log.info("got management type id : " + typeId);
				ManagementClientType managementClientType = kepengurusanKlienService
						.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("managementType.id", typeId));
				
				if (managementClientType != null) {
					log.info("got kepengurusan klien with kepengurusan : " + managementClientType.getManagementType().getName());
					if (!listKepengurusanIdsChecked.contains(managementClientType.getManagementType().getId())) {
						log.info("unchecked, delete it..!");
						kepengurusanKlienService.delete(managementClientType);
					} else {
						log.info("still checked");
					}
				} else {
					log.info("management client is null");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	private void savingAktaConfiguration(List<Integer> listAktaIdsChecked) {
		try {
			for (Integer id : listAktaIdsChecked) {
			
				log.info("akta id : " + id);
				Category akta = categoryService.findById(id);
				System.out.println("akta : " + akta.getName());
				
				// ============== CLIENT CERTIFICATE / AKTA KLIEN / tb_client_certificate
				// Checking availability on tb_client_certificate table
				ClientCertificate aktaKlien = aktaKlienService
						.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("certificateType", akta));
				if (aktaKlien != null) {
					log.info("this akta already exist as akta klien. update...");
					aktaKlien.setUpdateDate(new Timestamp(System.currentTimeMillis()));
					aktaKlien.setUpdateBy(user.getLoginId());
				} else {
					log.info("this kepengurusan not found as kepengurusan klien. add...");
					aktaKlien = new ClientCertificate();
					aktaKlien.setCertificateType(akta);
					aktaKlien.setClient(klien);
					aktaKlien.setCreateDate(new Timestamp(System.currentTimeMillis()));
					aktaKlien.setCreateBy(user.getLoginId());
				}
				
				// Saving into tb_client_certificate
				aktaKlienService.save(aktaKlien);
				log.sInfo("AKTA [%s] WAS SAVED INTO AKTA KLIEN (tb_client_certificate)", aktaKlien.getCertificateType().getName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void savingKepengurusanConfiguration(List<Integer> listKepengurusanIdsChecked) {
		try {
			for (Integer id : listKepengurusanIdsChecked) {
			
				log.info("kepengurusan notaris id : " + id);
				Category kepengurusan = categoryService.findById(id);
				System.out.println("kepengurusan : " + kepengurusan.getName());
				
				// ============== MANAGEMENT CLIENT TYPE / KEPENGURUSAN KLIEN / tb_management_client_type
				// Checking availability on tb_management_client_type table
				ManagementClientType kepengurusanKlien = kepengurusanKlienService
						.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("managementType", kepengurusan));
				if (kepengurusanKlien != null) {
					log.info("this kepengurusan already exist as kepengurusan klien. update...");
					kepengurusanKlien.setUpdateDate(new Timestamp(System.currentTimeMillis()));
					kepengurusanKlien.setUpdateBy(user.getLoginId());
				} else {
					log.info("this kepengurusan not found as kepengurusan klien. add...");
					kepengurusanKlien = new ManagementClientType();
					kepengurusanKlien.setManagementType(kepengurusan);
					kepengurusanKlien.setClient(klien);
					kepengurusanKlien.setCreateDate(new Timestamp(System.currentTimeMillis()));
					kepengurusanKlien.setCreateBy(user.getLoginId());
				}
				
				// Saving into tb_management_client_type
				kepengurusanKlienService.save(kepengurusanKlien);
				log.sInfo("KEPENGURUSAN [%s] WAS SAVED INTO KEPENGURUSAN KLIEN (tb_management_client_type)", kepengurusanKlien.getManagementType().getName());
				
				// ============== MANAGEMENT / PROSES KEPENGURUSAN / tb_management
				// Checking availability on tb_management
				Management prosesKepengurusan = prosesKepengurusanService
						.findByCriteria(Restrictions.eq("client", klien), Restrictions.eq("managementType", kepengurusan));
				
				if (prosesKepengurusan != null) {
					log.info("this kepengurusan already exist as proses kepengurusan. update...");
					prosesKepengurusan.setUpdateDate(new Timestamp(System.currentTimeMillis()));
					prosesKepengurusan.setUpdateBy(user.getLoginId());
				} else {
					log.info("this kepengurusan not found as proses kepengurusan. add...");
					prosesKepengurusan = new Management();
					prosesKepengurusan.setManagementType(kepengurusan);
					prosesKepengurusan.setClient(klien);
					prosesKepengurusan.setCreateDate(new Timestamp(System.currentTimeMillis()));
					prosesKepengurusan.setCreateBy(user.getLoginId());
				}
				
				// Saving into tb_management
				prosesKepengurusanService.save(prosesKepengurusan);
				log.sInfo("PROSES KEPENGURUSAN [%s] WAS SAVED INTO PROSES KEPENGURUSAN KLIEN (tb_management)", prosesKepengurusan.getManagementType().getName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String lookingForKetDokumen(int dokumenId, int klienId) {
		try {
			for (ClientDocument clientDocument : klien.getClientDocuments()) {
				if (clientDocument.getDocumentType().getId() == dokumenId) {
					return String.valueOf(clientDocument.getDocumentRemarks().getId());	
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	
	// =======================================================================================================================================
	// =======================================================================================================================================
	
	@Override
	@SkipValidation
	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	public String[] getKepengurusanNotarisIds() {
		return kepengurusanNotarisIds;
	}

	public void setKepengurusanNotarisIds(String[] kepengurusanNotarisIds) {
		this.kepengurusanNotarisIds = kepengurusanNotarisIds;
	}

	public String[] getAktaPPATIds() {
		return aktaPPATIds;
	}

	public void setAktaPPATIds(String[] aktaPPATIds) {
		this.aktaPPATIds = aktaPPATIds;
	}

	public String[] getKepengurusanPPATIds() {
		return kepengurusanPPATIds;
	}

	public void setKepengurusanPPATIds(String[] kepengurusanPPATIds) {
		this.kepengurusanPPATIds = kepengurusanPPATIds;
	}

	public String[] getJenisDokumenIds() {
		return jenisDokumenIds;
	}

	public void setJenisDokumenIds(String[] jenisDokumenIds) {
		this.jenisDokumenIds = jenisDokumenIds;
	}

	@Override
	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@SkipValidation
	public String detail() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@SkipValidation
	public String delete() {
		// TODO Auto-generated method stub
		return null;
	}

	public int getId() {
		return id;
	}

	public void setId(String id) {
		System.out.println("id : " + id);
		int id_ = 0;
		if(id != null && !id.equalsIgnoreCase("0")) {
			id = GlobalFunction.decodeParameter(id);
	        id_ = Integer.parseInt(id);
		}
        this.id = id_;
	}

	public Client getKlien() {
		return klien;
	}

	public void setKlien(Client klien) {
		this.klien = klien;
	}

	public List<Client> getListKlien() {
		return listKlien;
	}

	public void setListKlien(List<Client> listKlien) {
		this.listKlien = listKlien;
	}

	public List<Category> getListTipeDepartemen() {
		return listTipeDepartemen;
	}

	public void setListTipeDepartemen(List<Category> listTipeDepartemen) {
		this.listTipeDepartemen = listTipeDepartemen;
	}

	public List<Category> getListJenisDokumen() {
		return listJenisDokumen;
	}

	public void setListJenisDokumen(List<Category> listJenisDokumen) {
		this.listJenisDokumen = listJenisDokumen;
	}

	public List<Category> getListStatusPembeli() {
		return listStatusPembeli;
	}

	public void setListStatusPembeli(List<Category> listStatusPembeli) {
		this.listStatusPembeli = listStatusPembeli;
	}

	public List<Category> getListAktaNotaris() {
		return listAktaNotaris;
	}

	public void setListAktaNotaris(List<Category> listAktaNotaris) {
		this.listAktaNotaris = listAktaNotaris;
	}

	public List<Category> getListKepengurusanNotaris() {
		return listKepengurusanNotaris;
	}

	public void setListKepengurusanNotaris(List<Category> listKepengurusanNotaris) {
		this.listKepengurusanNotaris = listKepengurusanNotaris;
	}

	public List<Category> getListAktaPPAT() {
		return listAktaPPAT;
	}

	public void setListAktaPPAT(List<Category> listAktaPPAT) {
		this.listAktaPPAT = listAktaPPAT;
	}

	public List<Category> getListKepengurusanPPAT() {
		return listKepengurusanPPAT;
	}

	public void setListKepengurusanPPAT(List<Category> listKepengurusanPPAT) {
		this.listKepengurusanPPAT = listKepengurusanPPAT;
	}


	public int getStatusPembeliId() {
		return statusPembeliId;
	}

	public void setStatusPembeliId(String statusPembeliId) {
		int id_ = 0;
		if(statusPembeliId != null && !statusPembeliId.equalsIgnoreCase("0")) {
			statusPembeliId = GlobalFunction.decodeParameter(statusPembeliId);
	        id_ = Integer.parseInt(statusPembeliId);
		}
        this.statusPembeliId = id_;
	}

	public int getDepartemenId() {
		return departemenId;
	}

	public void setDepartemenId(String departemenId) {
		int id_ = 0;
		if(departemenId != null && !departemenId.equalsIgnoreCase("0")) {
			departemenId = GlobalFunction.decodeParameter(departemenId);
	        id_ = Integer.parseInt(departemenId);
		}
        this.departemenId = id_;
	}
	
	public Debitur getDebitur() {
		return debitur;
	}

	public void setDebitur(Debitur debitur) {
		this.debitur = debitur;
	}

	public Seller getSeller() {
		return seller;
	}

	public void setSeller(Seller seller) {
		this.seller = seller;
	}

	public Category getDepartemen() {
		return departemen;
	}

	public void setDepartemen(Category departemen) {
		this.departemen = departemen;
	}

	public SignatureSchedule getSignatureSchedule() {
		return signatureSchedule;
	}

	public void setSignatureSchedule(SignatureSchedule signatureSchedule) {
		this.signatureSchedule = signatureSchedule;
	}

	public Tax getTax() {
		return tax;
	}

	public void setTax(Tax tax) {
		this.tax = tax;
	}

	public String getTanggalPembayaran() {
		return tanggalPembayaran;
	}

	public void setTanggalPembayaran(String tanggalPembayaran) {
		this.tanggalPembayaran = tanggalPembayaran;
	}

	public String getJamTTD() {
		return jamTTD;
	}

	public void setJamTTD(String jamTTD) {
		this.jamTTD = jamTTD;
	}

	public String getTglTTD() {
		return tglTTD;
	}

	public void setTglTTD(String tglTTD) {
		this.tglTTD = tglTTD;
	}

	public void setDepartemenId(int departemenId) {
		this.departemenId = departemenId;
	}

	public String getTempatTTD() {
		return tempatTTD;
	}

	public void setTempatTTD(String tempatTTD) {
		this.tempatTTD = tempatTTD;
	}

	public String[] getAktaNotarisIds() {
		return aktaNotarisIds;
	}

	public void setAktaNotarisIds(String[] aktaNotarisIds) {
		this.aktaNotarisIds = aktaNotarisIds;
	}

	public List<Category> getListKeteranganDokumen() {
		return listKeteranganDokumen;
	}

	public void setListKeteranganDokumen(List<Category> listKeteranganDokumen) {
		this.listKeteranganDokumen = listKeteranganDokumen;
	}

	public String[] getKeteranganDokumenIds() {
		return keteranganDokumenIds;
	}

	public void setKeteranganDokumenIds(String[] keteranganDokumenIds) {
		this.keteranganDokumenIds = keteranganDokumenIds;
	}

	public List<Integer> getListDokumenId() {
		return listDokumenId;
	}

	public void setListDokumenId(List<Integer> listDokumenId) {
		this.listDokumenId = listDokumenId;
	}

	public List<Category> getListBank() {
		return listBank;
	}

	public void setListBank(List<Category> listBank) {
		this.listBank = listBank;
	}

	public int getBankId() {
		return bankId;
	}

	public void setBankId(String bankId) {
		int id_ = 0;
		if(bankId != null && !bankId.equalsIgnoreCase("0")) {
			bankId = GlobalFunction.decodeParameter(bankId);
	        id_ = Integer.parseInt(bankId);
		}
        this.bankId = id_;
	}

	public int getIsNotaris() {
		return isNotaris;
	}

	public void setIsNotaris(int isNotaris) {
		this.isNotaris = isNotaris;
	}

	public int getIsPPAT() {
		return isPPAT;
	}

	public void setIsPPAT(int isPPAT) {
		this.isPPAT = isPPAT;
	}

	public List<DokumenHelper> getListDokumenHelper() {
		return listDokumenHelper;
	}

	public void setListDokumenHelper(List<DokumenHelper> listDokumenHelper) {
		this.listDokumenHelper = listDokumenHelper;
	}

	public List<Integer> getListKeteranganDokumenId() {
		return listKeteranganDokumenId;
	}

	public void setListKeteranganDokumenId(List<Integer> listKeteranganDokumenId) {
		this.listKeteranganDokumenId = listKeteranganDokumenId;
	}

	public String getBtn() {
		return btn;
	}

	public void setBtn(String btn) {
		this.btn = btn;
	}

	public List<Integer> getListAktaNotarisId() {
		return listAktaNotarisId;
	}

	public void setListAktaNotarisId(List<Integer> listAktaNotarisId) {
		this.listAktaNotarisId = listAktaNotarisId;
	}

	public List<Integer> getListKepengurusanNotarisId() {
		return listKepengurusanNotarisId;
	}

	public void setListKepengurusanNotarisId(
			List<Integer> listKepengurusanNotarisId) {
		this.listKepengurusanNotarisId = listKepengurusanNotarisId;
	}

	public List<Integer> getListAktaPPATId() {
		return listAktaPPATId;
	}

	public void setListAktaPPATId(List<Integer> listAktaPPATId) {
		this.listAktaPPATId = listAktaPPATId;
	}

	public List<Integer> getListKepengurusanPPATId() {
		return listKepengurusanPPATId;
	}

	public void setListKepengurusanPPATId(List<Integer> listKepengurusanPPATId) {
		this.listKepengurusanPPATId = listKepengurusanPPATId;
	}

	public String getNominalPajakSSB() {
		return nominalPajakSSB;
	}

	public void setNominalPajakSSB(String nominalPajakSSB) {
		this.nominalPajakSSB = nominalPajakSSB;
	}

	public String getNominalPajakSSP() {
		return nominalPajakSSP;
	}

	public void setNominalPajakSSP(String nominalPajakSSP) {
		this.nominalPajakSSP = nominalPajakSSP;
	}

	public String getNamaDebitur() {
		return namaDebitur;
	}

	public void setNamaDebitur(String namaDebitur) {
		this.namaDebitur = namaDebitur;
	}

	public String getNamaSertifikat() {
		return namaSertifikat;
	}

	public void setNamaSertifikat(String namaSertifikat) {
		this.namaSertifikat = namaSertifikat;
	}

	public String getNomorSertifikat() {
		return nomorSertifikat;
	}

	public void setNomorSertifikat(String nomorSertifikat) {
		this.nomorSertifikat = nomorSertifikat;
	}

	public List<Certificate> getListSertifikat() {
		return listSertifikat;
	}

	public void setListSertifikat(List<Certificate> listSertifikat) {
		this.listSertifikat = listSertifikat;
	}

	public String[] getSelectedRows() {
		return selectedRows;
	}

	public void setSelectedRows(String[] selectedRows) {
		this.selectedRows = selectedRows;
	}

	public int getStatusPasanganKawinPembeliId() {
		return statusPasanganKawinPembeliId;
	}

	public void setStatusPasanganKawinPembeliId(String statusPasanganKawinPembeliId) {
		int id_ = 0;
		if(statusPasanganKawinPembeliId != null && !statusPasanganKawinPembeliId.equalsIgnoreCase("0")) {
			statusPasanganKawinPembeliId = GlobalFunction.decodeParameter(statusPasanganKawinPembeliId);
	        id_ = Integer.parseInt(statusPasanganKawinPembeliId);
		}
        this.statusPasanganKawinPembeliId = id_;
	}

	public boolean isPT() {
		return PT;
	}

	public void setPT(boolean pT) {
		PT = pT;
	}
}
